<template>
  <div>

    <loading-view :data="rankingList">
      <div>
        <div class="rankingBackView">
          <div class="headerView">
            <div>
              <p class="nameLabel">排行榜 Top100</p>
              <p class="tagLabel">距离NO.1你还差一丢丢努力</p>
            </div>
            <img class="imgView" src="/web-hft-ee/static/img/m/ranking_list_trophy.png">
          </div>
          <div class="listView">
            <ranking-unit-view></ranking-unit-view>
            <van-list v-model="loading"
                      :offset="offset"
                      :finished="finished"
                      @load="getChartData(false)">
              <div v-for="(el, idx) in rankingList" style="padding-bottom: 16px">
                <ranking-cell :ranking-index="idx" :data="el"></ranking-cell>
              </div>
            </van-list>

          </div>
          <div style="height: 32px"></div>
        </div>
      </div>

    </loading-view>

  </div>

</template>

<script>

  import UniversityTool from '@/pages/university/UniversityTool'
  import RankingUnitView from './components/RankingUnitView'
  import RankingCell from './components/RankingCell'
  import LevelCover from '../components/LevelCover'
  import LoadingView from '@/components/LoadingView'

  export default {
    name: "ranking-total",
    data() {
      return {
        nextPage: 1,///下一次请求的页码
        loading: false,//数据加载中
        finished: false,///所有数据加载完成，没有更多
        offset: 10,
        rankingList: [],
      }
    },
    components: {
      RankingCell,
      RankingUnitView,
      LevelCover,
      LoadingView
    },
    computed: {

    },
    mounted() {
      this.getChartData(true)
    },
    methods: {

      getChartData(isRefresh) {

        this.loading = true
        if (isRefresh) {
          this.nextPage = 1
        }
        let teamId = this.$store.getters.enterpriseInfo.enterprise.id
        UniversityTool.getRankingData(teamId, 1, this.nextPage).then((list) => {

          this.nextPage += 1
          this.finished = list.length === 0 || this.nextPage > 5

          if (isRefresh) {
            this.rankingList = list
          } else {
            this.rankingList = this.rankingList.concat(list)
          }

        }).finally(() => {
          this.loading = false
        })
      }

    }
  }
</script>

<style scoped>
  .rankingBackView {
    min-height: 100vh;
    background-image: linear-gradient(to bottom, #FFD272, #FFA554);
  }

  .headerView {
    padding: 8px 0 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .nameLabel {
    color: white;
    font-size: 26px;
    font-weight: bold;

  }

  .tagLabel {
    font-size: 14px;
    color: white;
    margin-top: 8px;

  }

  .imgView {
    width: 50%;
    object-fit: cover;
  }

  .listView {
    margin: 16px 16px 16px 16px;
    padding: 16px 16px 0 16px;
    background-color: white;
    border-radius: 12px;

  }
</style>
